Create attribute filter

Dear all,

I am a newbe in DXL world, I would appreciate any suggestions.

I have to create an attribute B that filters the attribute A.

If A contains "YES" B must be "YES".

I tried with something like

if (o."A".contains("YES")) o."B"="YES"   

but it is not correct.

Where can I find a good guide for DXL?

Thanks in advance

 


Dario_Imparato - Tue Sep 22 12:17:46 EDT 2015

Re: Create attribute filter
PekkaMakinen - Wed Sep 23 00:36:06 EDT 2015

The ONLY guide to DXL is the DXL Reference Manual available through your DOORS client: Help / DXL Reference Manual.

If you do a net search for "DXL tutorial" you might also find some information to start yourself up on DXL.

 

On filters: read the DXL reference section on filters, note it has also a filters example program showing how to use filtering commands in DXL.

Re: Create attribute filter
PekkaMakinen - Wed Sep 23 04:33:34 EDT 2015

And also of course this forum, use the search here to find examples on setting an attribute filter by DXL
 

Re: Create attribute filter
Dario_Imparato - Wed Sep 23 04:44:07 EDT 2015

PekkaMakinen - Wed Sep 23 00:36:06 EDT 2015

The ONLY guide to DXL is the DXL Reference Manual available through your DOORS client: Help / DXL Reference Manual.

If you do a net search for "DXL tutorial" you might also find some information to start yourself up on DXL.

 

On filters: read the DXL reference section on filters, note it has also a filters example program showing how to use filtering commands in DXL.

Hello PekkaMakinen,

thank you for your answer.

I used the following code to solve my problem (it could be useful for others):


Object o
for o in current Module do {
string stringToAnalyze=o."attribute1"
string sub="pippo"
int offset=null
int length=null
bool matchCase=false
bool reverse=false
if (findPlainText (stringToAnalyze, sub, offset, length, matchCase, reverse)){
    o."attribute2" = "YES"
}
}

 

Re: Create attribute filter
llandale - Sat Sep 26 16:12:42 EDT 2015

You don't want a filter.

Attribute "B" should be defined as an attribute-DXL, presumably of type "string"

Buffer buf = create

buf = obj."A"

if (contains(buf, "YES", 0) > 0 //

then obj.attrDXLName = "YES"

else obj.attrDXLName = "NO"

delete(buf)

This presumes you do not want to match "YES" in a work "XYES" nor "YESPLEASE".  The buffer "contains" is looking for a word.  If you DO want to match those, then forget the buffer and try

  • if (matches("YES", obj."A" "")

When you are done with that you can define a view that "Filters" on whether attribute "B" is "YES".

-Louie

Re: Create attribute filter
Dario_Imparato - Mon Sep 28 15:47:09 EDT 2015

llandale - Sat Sep 26 16:12:42 EDT 2015

You don't want a filter.

Attribute "B" should be defined as an attribute-DXL, presumably of type "string"

Buffer buf = create

buf = obj."A"

if (contains(buf, "YES", 0) > 0 //

then obj.attrDXLName = "YES"

else obj.attrDXLName = "NO"

delete(buf)

This presumes you do not want to match "YES" in a work "XYES" nor "YESPLEASE".  The buffer "contains" is looking for a word.  If you DO want to match those, then forget the buffer and try

  • if (matches("YES", obj."A" "")

When you are done with that you can define a view that "Filters" on whether attribute "B" is "YES".

-Louie

Do you mean contains is similar to java contains and matches is similar to equals?

Re: Create attribute filter
llandale - Wed Sep 30 09:58:00 EDT 2015

Dario_Imparato - Mon Sep 28 15:47:09 EDT 2015

Do you mean contains is similar to java contains and matches is similar to equals?

I don't use "contains".  I don't know anything about java.

"contains" in a buffer is looking for some kind of "word".

int contains(Buffer b, string word, int offset)

... returns the index at which string word appears in the buffer, starting from 0, provided the string is preceded by a non-alphanumeric character. The value of the mandatory offset argument controls where the search starts. If word does not appear after offset, the function returns -1.

So I guess it won't find "XYES" but will find " YESPLEASE".

"matches" is looking for the string exactly anywhere.  Be advised that "matches" is particularly inefficient as it creates allocated unit "Regexp" each time.  This is better:

Regexp reHasYes = regexp2("YES")    // at top of program

....

if (reHasYes  obj."A" "") ...

-Louie

Errata: I see the word "after" at the end of the description.  it appears I should have a "-1" instead of "0" in this line of code:

if (contains(buf, "YES", -1) > 0 //